package com.hmdp.controller;


import com.hmdp.dto.Result;
import com.hmdp.service.IFollowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 豪哥
 */
@Api(tags = "关注相关接口")
@RestController
@RequestMapping("/follow")
public class FollowController {

    @Resource
    private IFollowService followService;

    @ApiOperation(value = "关注/取关", notes = "关注或取关指定用户")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "要关注的用户id", required = true, dataType = "Long", paramType = "path"),
        @ApiImplicitParam(name = "isFollow", value = "true表示关注，false表示取关", required = true, dataType = "Boolean", paramType = "path")
    })
    @PutMapping("/{id}/{isFollow}")
    public Result follow(@PathVariable("id") Long followUserId, @PathVariable("isFollow") Boolean isFollow) {
        return followService.follow(followUserId, isFollow);
    }

    @ApiOperation(value = "判断是否关注", notes = "判断是否已关注指定用户")
    @ApiImplicitParam(name = "id", value = "用户id", required = true, dataType = "Long", paramType = "path")
    @GetMapping("/or/not/{id}")
    public Result isFollow(@PathVariable("id") Long followUserId) {
        return followService.isFollow(followUserId);
    }

    @ApiOperation(value = "共同关注", notes = "获取共同关注的用户列表")
    @ApiImplicitParam(name = "id", value = "用户id", required = true, dataType = "Long", paramType = "path")
    @GetMapping("/common/{id}")
    public Result followCommons(@PathVariable("id") Long id){
        return followService.followCommons(id);
    }
}
